package com.grow.greenhouse.controller;

import com.alibaba.fastjson.JSON;
import com.grow.greenhouse.domain.Systemthreshold;
import com.grow.greenhouse.domain.Userthreshold;
import com.grow.greenhouse.service.SystemthreholdService;
import com.grow.greenhouse.service.UserthreholdService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/insert")
public class testInsertValueController {

    @Resource
    private SystemthreholdService systemthreholdService;

    @Resource
    private UserthreholdService userthreholdService;

    @GetMapping("/doit")
    public String insertIntoSystemthrehold(){

        Systemthreshold systemthreshold = new Systemthreshold();
        systemthreshold.setCropName("白菜");

        systemthreshold.setCropName("西红柿");

        // 设置各项指标的阈值
        systemthreshold.setSoilTemp(JSON.toJSONString(Arrays.asList("12", "20.5", "30")));
        systemthreshold.setSoilMoisture(JSON.toJSONString(Arrays.asList("50", "75", "100"))); // 未给出具体数值
        systemthreshold.setAirTemp(JSON.toJSONString(Arrays.asList("10", "22.5", "32")));
        systemthreshold.setAirMoisture(JSON.toJSONString(Arrays.asList("60", "70", "90")));
        systemthreshold.setIllumination(JSON.toJSONString(Arrays.asList("25000", "37500", "50000")));
        systemthreshold.setCarbonDioxide(JSON.toJSONString(Arrays.asList("400", "700", "1000")));
        systemthreshold.setPHvalue(JSON.toJSONString(Arrays.asList("6.0", "6.5", "7.5")));

        // 插入数据
        systemthreholdService.save(systemthreshold);
        return "插入成功";
    }
    @GetMapping("/doparse")
    public String parseSystemthrehold(){

        List<Systemthreshold> list = systemthreholdService.list();
        Userthreshold userthreshold = new Userthreshold();
        for(Systemthreshold systemthreshold : list){
            BeanUtils.copyProperties(systemthreshold, userthreshold);

        }


        return "插入成功";
    }

}
